//
//
//
//using system;
//using jarlUtils;

/* 
 transform to c++ abstract tree
 - all clone statments and clone.do
   get turned into constructors
*/

getArgs (IdJarl (Id "args") X) = getArgs2 X;
getArgs2 X           = getArgs3 A if (#X)==1 when A = (X!0) end;
getArgs2 ((Id A):AS) = A + "," + getArgs2 AS;
getArgs2 (A:AS)      = str A + "," + getArgs2 AS;
getArgs3 (Id A) = A;
getArgs3 A      = str A;

genConstr X = sprintf "   %s %s;\n" (T,L) if (#X)==2
              when (Id T) = (X!0); 
                   (Id L) = (X!1) end;
         
            = sprintf "   %s %s(%s);\n" (T,L,A) if (#X)==3
              when (Id T) = (X!0); 
                   (Id L) = (X!1);
                   A = getArgs (X!2) end;
                   
            = genConstr_error otherwise;

objLayoutAdd SELF VIEW =
/*|[
  %s << %s;                [SELF,VIEW] 
]|*/
  "";

glvGenCppPre =
/*|[
/*	Graphics Library of Views (GLV) - GUI Building Toolkit
	this file was auto generated by glvGenCpp.pure */

#include <math.h>
#include "glv.h"
#include "glv_pimpl_binding.h"

using namespace glv;
]|*/
  "";

glvGenCppMain AST =
/*|[
int main(int argc, char ** argv){
]|*/
  glvGenCppMainBody AST +
/*|[
   return 0;
}
]|*/
  "";

glvGenCppMainBody 
 ((IdJarl (Id ["Cpp","Constructor"]) X):AST) = genConstr X + glvGenCppMainBody AST;

glvGenCppMainBody [] = "";

glvGenCpp AST =
  
  glvGenCppPre +
  glvGenCppMain AST;
